package com.jit.monitor.app;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.text.TextUtils;
import android.util.Log;

import com.jit.baselib.baseapp.BaseApp;
import com.jit.monitor.model.CheckDataManager;
import com.jit.monitor.model.cache.UserCache;
import com.jit.monitor.util.BuglyHelper;
import com.jit.monitor.util.JPushHelper;
import com.tencent.bugly.crashreport.CrashReport;

import org.litepal.LitePal;

import cn.jpush.android.api.JPushInterface;

/**
 * @author 张先磊
 * @date 2018/4/17
 */

public class MyApp extends BaseApp {
    @Override
    public void onCreate() {
        super.onCreate();
        // litePal初始化
        LitePal.initialize(this);
        // 初始化Bugly
        BuglyHelper.getInstance().initBuglyApp(this);
        initJPush();
        CheckDataManager.doInit();
    }

    /**
     * 初始化JPush---
     */
    private void initJPush(){
        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);
        // 设置别名
        JPushHelper.getInstance().setAlias();
    }

    public static boolean isNetworkConnected() {
        Context context = MyApp.getContext();
        if (context != null) {
            ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            if (null == mConnectivityManager){
                return false;
            }
            NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();

            if (mNetworkInfo != null) {
                return mNetworkInfo.isAvailable();
            }
        }
        return false;
    }
}
